﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
    /// <summary>
    /// MD5
    /// </summary>
    public class MD5Helper
    {
        /// <summary>
        /// MD5 16位加密
        /// </summary>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public string MD5Encryption16(string pwd)
        {
            var md5 = new MD5CryptoServiceProvider();
            string t2 = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(pwd)),4,8);
            t2 = t2.Replace("-","");
            return t2;
        }
        /// <summary>
        /// MD5 64位加密
        /// </summary>
        /// <returns></returns>
        public string MD5Encryption64(string pwd)
        {
            MD5 md5 = MD5.Create(); //实例化一个md5对像
            // 加密后是一个字节类型的数组，这里要注意编码UTF8/Unicode等的选择　
            byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(pwd));
            return Convert.ToBase64String(s);
        }
    }
}
